home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 5 / MacMania 5.toast / / Internet software / NewsWatcher / NW Source / Shared Code / Libraries & Misc / OpenTptInternet.h < prev    next >
Text File  |  1996-10-01  |  10KB  |  376 lines

  1. /*
  2.     File:        OpenTptInternet.h
  3.  
  4.     Contains:    Client TCP/IP definitions
  5.  
  6.     Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  7.  
  8.  
  9. */
  10.  
  11.  
  12. #ifndef __OPENTPTINTERNET__
  13. #define __OPENTPTINTERNET__
  14.  
  15. #ifndef __OPENTRANSPORT__
  16. #include <OpenTransport.h>
  17. #endif    
  18. #if PRAGMA_ALIGN_SUPPORTED
  19. #pragma options align=mac68k
  20. #endif
  21. #if PRAGMA_IMPORT_SUPPORTED
  22. #pragma import on
  23. #endif
  24.  
  25. /*******************************************************************************
  26. ** Misc 
  27. ********************************************************************************/
  28.  
  29. typedef UInt16    InetPort;
  30. typedef UInt32    InetHost;
  31.  
  32. //
  33. //    Enums used as address type designations.
  34. //
  35. enum
  36. {
  37.     AF_INET                = 2,    // Traditonal
  38.     AF_DNS                = 42    // Obviously, the answer to...
  39. };
  40.  
  41. //
  42. //    Enum which can be used to bind to all IP interfaces
  43. //    rather than a specific one.
  44. //
  45. enum
  46. {
  47.     kOTAnyInetAddress    = 0        // Wildcard
  48. };
  49.  
  50. #ifdef __cplusplus
  51.     class    TInternetServices;
  52.     typedef TInternetServices*    InetSvcRef;
  53. #else
  54.     typedef void*    InetSvcRef;
  55. #endif
  56.  
  57. /*******************************************************************************
  58. ** Some prefixes for shared libraries
  59. ********************************************************************************/
  60.  
  61. #define kInetVersion    "3.1.1"
  62. #define kInetPrefix        "ot:inet$"
  63.  
  64. /*******************************************************************************
  65. ** Module Names
  66. ********************************************************************************/
  67. #define kDNRName        "dnr"
  68. #define kTCPName        "tcp"
  69. #define kUDPName        "udp"
  70. #define kRawIPName        "rawip"
  71.  
  72. /*******************************************************************************
  73. ** XTI Options
  74. ********************************************************************************/
  75.  
  76. // Protocol levels
  77.  
  78. #define    INET_IP         0x0
  79. #define    INET_TCP     0x06
  80. #define    INET_UDP     0x11
  81.  
  82.  
  83. // TCP Level Options
  84.  
  85. #define    TCP_NODELAY                     0x01
  86. #define    TCP_MAXSEG                     0x02
  87. #define TCP_NOTIFY_THRESHOLD        0x10    /** not a real XTI option */
  88. #define TCP_ABORT_THRESHOLD            0x11    /** not a real XTI option */
  89. #define TCP_CONN_NOTIFY_THRESHOLD    0x12    /** not a real XTI option */
  90. #define TCP_CONN_ABORT_THRESHOLD    0x13    /** not a real XTI option */
  91. #define TCP_OOBINLINE                0x14    /** not a real XTI option */
  92. #define TCP_URGENT_PTR_TYPE            0x15    /** not a real XTI option */
  93. #define    TCP_KEEPALIVE                 OPT_KEEPALIVE    /* keepalive defined in OpenTransport.h */
  94.  
  95. #define    T_GARBAGE                     2            
  96.  
  97.  
  98. // UDP Level Options
  99.  
  100. #define    UDP_CHECKSUM        OPT_CHECKSUM
  101. #define UDP_RX_ICMP            0x2
  102.  
  103. // IP Level Options
  104.  
  105. #define    IP_OPTIONS             0x01
  106. #define    IP_TOS                 0x02
  107. #define    IP_TTL                 0x03
  108. #define    IP_REUSEADDR         0x04
  109. #define    IP_DONTROUTE         0x10
  110. #define    IP_BROADCAST         0x20
  111. #define    IP_HDRINCL             0x1002    
  112. #define IP_RCVOPTS             0x1005
  113. #define IP_RCVDSTADDR         0x1007
  114. #define    IP_MULTICAST_IF         0x1010        /* set/get IP multicast interface    */
  115. #define    IP_MULTICAST_TTL     0x1011        /* set/get IP multicast timetolive    */
  116. #define    IP_MULTICAST_LOOP     0x1012        /* set/get IP multicast loopback    */
  117. #define    IP_ADD_MEMBERSHIP     0x1013        /* add an IP group membership        */
  118. #define    IP_DROP_MEMBERSHIP     0x1014        /* drop an IP group membership        */
  119. #define    IP_BROADCAST_IF         0x1015        /* Set interface for broadcasts     */
  120. #define    IP_RCVIFADDR         0x1016        /* Set interface for broadcasts     */
  121.  
  122. //    DVMRP-specific setsockopt commands, from ip_mroute.h
  123. //
  124. #define    DVMRP_INIT        100
  125. #define    DVMRP_DONE        101
  126. #define    DVMRP_ADD_VIF    102
  127. #define    DVMRP_DEL_VIF    103
  128. #define    DVMRP_ADD_LGRP    104
  129. #define    DVMRP_DEL_LGRP    105
  130. #define    DVMRP_ADD_MRT    106
  131. #define    DVMRP_DEL_MRT    107
  132.  
  133. // IP_TOS precdence levels
  134. enum
  135. {
  136.     T_ROUTINE        = 0,
  137.     T_PRIORITY        = 1,
  138.     T_IMMEDIATE        = 2,
  139.     T_FLASH            = 3,
  140.     T_OVERRIDEFLASH    = 4,
  141.     T_CRITIC_ECP    = 5,
  142.     T_INETCONTROL    = 6,
  143.     T_NETCONTROL    = 7
  144. };
  145.  
  146. //    IP_TOS type of service
  147. enum
  148. {
  149.     T_NOTOS        = 0x0,        
  150.     T_LDELAY    = (1<<4),
  151.     T_HITHRPT    = (1<<3),
  152.     T_HIREL     = (1<<2)
  153. };
  154.  
  155. #define    SET_TOS(prec,tos)    (((0x7 & (prec)) << 5) | (0x1c & (tos)))
  156.  
  157. // IP Multicast option structures
  158. struct TIPAddMulticast
  159. {
  160.     InetHost multicastGroupAddress;
  161.     InetHost interfaceAddress;
  162. };
  163. typedef struct TIPAddMulticast TIPAddMulticast;
  164.  
  165.  
  166. /*******************************************************************************
  167. ** Protocol-specific events
  168. ********************************************************************************/
  169.  
  170. enum
  171. {
  172.     T_DNRSTRINGTOADDRCOMPLETE    = kPRIVATEEVENT+1,
  173.     T_DNRADDRTONAMECOMPLETE        = kPRIVATEEVENT+2,
  174.     T_DNRSYSINFOCOMPLETE        = kPRIVATEEVENT+3,
  175.     T_DNRMAILEXCHANGECOMPLETE    = kPRIVATEEVENT+4,
  176.     T_DNRQUERYCOMPLETE            = kPRIVATEEVENT+5
  177. };
  178.  
  179. /*******************************************************************************
  180. ** InetAddress
  181. ********************************************************************************/
  182.  
  183. struct InetAddress
  184. {
  185.         OTAddressType    fAddressType;    // always AF_INET
  186.         InetPort        fPort;            // Port number 
  187.         InetHost        fHost;            // Host address in net byte order
  188.         UInt8            fUnused[8];        // Traditional unused bytes
  189. };
  190. typedef struct InetAddress InetAddress;
  191.  
  192. /*******************************************************************************
  193. ** Domain Name Resolver (DNR) 
  194. ********************************************************************************/
  195.  
  196. enum 
  197.         kMaxHostAddrs         =  10,
  198.         kMaxSysStringLen     =  32,
  199.         kMaxHostNameLen        = 255
  200. };
  201.  
  202. typedef char InetDomainName[kMaxHostNameLen + 1];
  203.  
  204. struct InetHostInfo
  205. {
  206.     InetDomainName    name;
  207.     InetHost        addrs[kMaxHostAddrs];
  208. };
  209. typedef struct InetHostInfo    InetHostInfo;
  210.  
  211. struct InetSysInfo
  212. {
  213.     char        cpuType[kMaxSysStringLen];
  214.     char        osType[kMaxSysStringLen];
  215. };
  216. typedef struct InetSysInfo InetSysInfo;
  217.  
  218. struct InetMailExchange
  219. {
  220.     UInt16            preference;
  221.     InetDomainName    exchange;
  222. };
  223. typedef struct InetMailExchange InetMailExchange;
  224.  
  225. struct DNSQueryInfo
  226. {
  227.     UInt16            qType;
  228.     UInt16            qClass;
  229.     UInt32            ttl;
  230.     InetDomainName    name;
  231.     UInt16            responseType;        // answer, authority, or additional
  232.     UInt16            resourceLen;        // actual length of array which follows
  233.     char            resourceData[4];    // size varies
  234. };
  235. typedef struct DNSQueryInfo DNSQueryInfo;
  236.  
  237.  
  238. /*******************************************************************************
  239. ** DNSAddress
  240. **
  241. **        The DNSAddress format is optional and may be used in connects,
  242. **        datagram sends, and resolve address calls.   The name takes the 
  243. **        format "somewhere.com" or "somewhere.com:portnumber" where
  244. **        the ":portnumber" is optional.   The length of this structure
  245. **        is arbitrarily limited to the overall max length of a domain
  246. **        name (255 chars), although a longer one can be use successfully
  247. **        if you use this as a template for doing so.   However, the domain name 
  248. **        is still limited to 255 characters.
  249. ********************************************************************************/
  250.  
  251. struct DNSAddress
  252. {
  253.     OTAddressType    fAddressType;    // always AF_DNS
  254.     InetDomainName    fName;            
  255. };
  256. typedef struct DNSAddress DNSAddress;
  257.  
  258. /*******************************************************************************
  259. ** InetInterfaceInfo
  260. ********************************************************************************/
  261.  
  262. struct InetInterfaceInfo
  263. {
  264.     InetHost        fAddress;
  265.     InetHost        fNetmask;
  266.     InetHost        fBroadcastAddr;
  267.     InetHost        fDefaultGatewayAddr;
  268.     InetHost        fDNSAddr;
  269.     UInt16            fVersion;
  270.     UInt16            fHWAddrLen;
  271.     UInt8*            fHWAddr;
  272.     UInt32            fIfMTU;
  273.     UInt8*            fReservedPtrs[2];
  274.     InetDomainName    fDomainName;
  275.     UInt8            fReserved[256];            
  276. };
  277. typedef struct InetInterfaceInfo InetInterfaceInfo;
  278.  
  279.  
  280.  
  281. /*******************************************************************************
  282. ** Static helper functions
  283. ********************************************************************************/
  284.  
  285. #ifdef __cplusplus
  286. extern "C" {
  287. #endif
  288.  
  289. extern pascal void             OTInitInetAddress(InetAddress* addr, InetPort port, InetHost host);
  290. extern pascal size_t        OTInitDNSAddress(DNSAddress* addr, char* str);
  291. extern pascal OSStatus         OTInetStringToHost(char* str, InetHost* host);
  292. extern pascal void          OTInetHostToString(InetHost host, char* str);
  293. extern pascal OSStatus         OTInetGetInterfaceInfo(InetInterfaceInfo* info, SInt32 val);
  294.  
  295. #ifdef __cplusplus
  296. }
  297. #endif
  298.  
  299.  
  300. /*******************************************************************************
  301. ** InetServices & DNR calls
  302. ********************************************************************************/
  303.  
  304. #define kDefaultInternetServicesPath    ((OTConfiguration*)-3)
  305.  
  306. #if !OTKERNEL
  307.  
  308. #ifdef __cplusplus
  309. extern "C" {
  310. #endif
  311.  
  312. extern pascal InetSvcRef     OTOpenInternetServices(OTConfiguration* cfig, OTOpenFlags oflag, OSStatus* err);
  313. extern pascal OSStatus        OTAsyncOpenInternetServices(OTConfiguration* cfig, OTOpenFlags oflag, 
  314.                                                         OTNotifyProcPtr proc, void* contextPtr);
  315. extern pascal OSStatus         OTInetStringToAddress(InetSvcRef ref, char* name,
  316.                                                   InetHostInfo* hinfo);
  317. extern pascal OSStatus         OTInetAddressToName(InetSvcRef ref, InetHost addr, 
  318.                                                 InetDomainName name);
  319. extern pascal OSStatus         OTInetSysInfo(InetSvcRef ref, char* name,
  320.                                           InetSysInfo* sysinfo);
  321. extern pascal OSStatus         OTInetMailExchange(InetSvcRef ref, char* name, UInt16* num,
  322.                                                InetMailExchange* mx);
  323.                                                
  324. extern pascal OSStatus        OTInetQuery(InetSvcRef ref, char* name, UInt16 qClass, UInt16 qType,
  325.                                           char* buf, size_t buflen, 
  326.                                         void** argv, size_t argvlen,
  327.                                         OTFlags flags);
  328.                     
  329.  
  330. #ifdef __cplusplus
  331. }
  332. #endif
  333.  
  334. enum
  335. {
  336.     kDefaultInetInterface    = -1,
  337.     kInetInterfaceInfoVersion    = 2
  338. };
  339.  
  340. #ifdef __cplusplus
  341.  
  342. class TInternetServices : public TProvider
  343. {
  344.     public:
  345.             OSStatus     StringToAddress(char* name, InetHostInfo* hinfo)
  346.                         { return OTInetStringToAddress(this, name, hinfo); }
  347.                     
  348.             OSStatus     AddressToName(InetHost addr, InetDomainName name)
  349.                         { return OTInetAddressToName(this, addr, name); }
  350.                     
  351.             OSStatus     SysInfo(char* name, InetSysInfo* sysinfo )
  352.                         { return OTInetSysInfo(this, name, sysinfo); }
  353.                     
  354.             OSStatus     MailExchange(char* name, UInt16* num, InetMailExchange* mx)
  355.                         { return OTInetMailExchange(this, name, num, mx); }
  356.                         
  357.             OSStatus    Query(char* name, UInt16 qClass, UInt16 qType, 
  358.                               char* buf, size_t buflen, 
  359.                               void** argv, size_t argvlen,
  360.                               OTFlags flags)
  361.                         { return OTInetQuery(this, name, qClass, qType, buf, buflen, argv, argvlen, flags); }
  362. };
  363.  
  364. #endif
  365. #endif        /* !OTKERNEL */
  366.  
  367. #if PRAGMA_ALIGN_SUPPORTED
  368. #pragma options align=reset
  369. #endif
  370. #if PRAGMA_IMPORT_SUPPORTED
  371. #pragma import off
  372. #endif
  373.  
  374. #endif    /* __OTINTERNET__ */
  375.